<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>本地存储</title>
  <script>
    <!--localStorage 对象存储的是没有截止日期的数据。当浏览器被关闭时数据不会被删除-->
    function clickCounter() {
      if(typeof(Storage) !== "undefined") {
        if (localStorage.clickcount) {
          localStorage.setItem("clickcount",Number(localStorage.clickcount)+1)
          // localStorage.clickcount = Number(localStorage.clickcount)+1;
        } else {
          localStorage.clickcount = 1;
        }
        // document.getElementById("result").innerHTML = "您已经点击这个按钮 " + localStorage.clickcount + " 次。"; 上下写法皆可
        document.getElementById("result").innerHTML = "您已经点击这个按钮 " + localStorage.getItem("clickcount") + " 次。";
      } else {
        document.getElementById("result").innerHTML = "抱歉！您的浏览器不支持 Web Storage ...";
      }
    }
  </script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">点击</button></p>
<div id="result"></div>
<p>关闭浏览器或标签页，计数器将继续计数（不会重置）。</p>
</body>
</html>